class_name PlayerGroundState
extends GameplayStateMachine

@onready var player: Player = $"../../"


func _on_setup() -> void:
	var multiway_transition: MultiwayStateTransition = MultiwayStateTransition.new(
		[
			func(): return\
				2 if player.input_handler.is_action_double_click_started_any(["move_left", "move_right"]) else\
				1 if player.input_handler.is_action_pressed_any(["move_left", "move_right"]) else\
				0
		],
		{
			[0]: "IdleState",
			[1]: "WalkState",
			[2]: "RunState",
		}
	)

	add_transition("GhostState", multiway_transition)
	add_transition("IdleState", multiway_transition)
	add_transition("WalkState", multiway_transition)
	add_transition("RunState", multiway_transition)

	var sword_transition = ConditionStateTransition.new(
		"SwordAttackState",
		func(): return player.weapon.equipment_name == "sword" and player.input_handler.is_action_just_pressed("attack"),
		func(): pass)
	add_transition("AnyState", sword_transition)

	var bow_transition = ConditionStateTransition.new(
		"BowAttackState",
		func(): return player.weapon.equipment_name == "bow" and player.input_handler.is_action_just_pressed("attack"),
		func(): pass)
	add_transition("AnyState", bow_transition)


func _on_enter() -> void:
	player.remove_tag(GameplayTagLibrary.Cooldown_Jump)
